'''
Author: SlytherinGe
LastEditTime: 2021-06-18 11:02:07
'''
_base_ = '../../fcos/fcos_r50_caffe_fpn_gn-head_4x4_1x_coco.py'
model = dict(
    pretrained='open-mmlab://msra/hrnetv2_w32',
    backbone=dict(
        _delete_=True,
        type='HRNet',
        extra=dict(
            stage1=dict(
                num_modules=1,
                num_branches=1,
                block='BOTTLENECK',
                num_blocks=(4, ),
                num_channels=(64, )),
            stage2=dict(
                num_modules=1,
                num_branches=2,
                block='BASIC',
                num_blocks=(4, 4),
                num_channels=(32, 64)),
            stage3=dict(
                num_modules=4,
                num_branches=3,
                block='BASIC',
                num_blocks=(4, 4, 4),
                num_channels=(32, 64, 128)),
            stage4=dict(
                num_modules=3,
                num_branches=4,
                block='BASIC',
                num_blocks=(4, 4, 4, 4),
                num_channels=(32, 64, 128, 256)))),
    neck=dict(
        _delete_=True,
        type='HRFPN',
        in_channels=[32, 64, 128, 256],
        out_channels=256,
        stride=2,
        num_outs=5),
    bbox_head=dict(
        _delete_=True,
        type='PAOIHead',
        in_channels=256,
        sigma=30,
        pos_thr = 0.8,
        neg_thr = 1e-15,
        target_ratio = 0.05,
        attention_stages=5,
        # dcn_on_last_conv=True,
        loss_attention=dict(
            type='GaussianFocalLoss',
            loss_weight=20.0),
        # loss_attention=dict(
        #     type='CrossEntropyLoss',
        #     use_sigmoid=True,
        #     loss_weight=5.0),
        # loss_attention=dict(
        #     type='SmoothL1Loss',
        #     loss_weight=5.0),
        # norm_cfg=dict(type='GN', num_groups=32, requires_grad=True),
        norm_cfg=dict(type='BN', requires_grad=True),
    )
    )
# # dataset settings
dataset_type = 'MyVOCDataset'
data_root = '/media/gejunyao/Disk1/Datasets/SSDD/'
img_norm_cfg = dict(
    mean=[39.7517759, 39.7517759, 39.7517759], std=[ 27.71722963, 27.71722963, 27.71722963], to_rgb=True)
train_pipeline = [
    dict(type='LoadImageFromFile'),
    dict(type='LoadAnnotations', with_bbox=True),
    dict(type='Resize', img_scale=(640, 640), keep_ratio=False),
    dict(type='EqualizeTransform'),
    dict(type='Rotate', level=1, prob=0.3),
    dict(type='BrightnessTransform', level=1, prob=0.3),
    dict(type='ContrastTransform', level=1, prob=0.3),
    dict(type='RandomFlip', flip_ratio=0.5),
    dict(type='Normalize', **img_norm_cfg),
    dict(type='DefaultFormatBundle'),
    dict(type='Collect', keys=['img', 'gt_bboxes', 'gt_labels']),
]
test_pipeline = [
    dict(type='LoadImageFromFile'),
    dict(
        type='MultiScaleFlipAug',
        img_scale=(640, 640),
        flip=False,
        transforms=[
            dict(type='Resize', keep_ratio=False),
            dict(type='Normalize', **img_norm_cfg),
            dict(type='ImageToTensor', keys=['img']),
            dict(type='Collect', keys=['img']),
        ])
]
data = dict(
    samples_per_gpu=12,
    workers_per_gpu=16,
    train=dict(
        type='RepeatDataset',
        times=1,
        dataset=dict(
            type=dataset_type,
            ann_file=[
                data_root + 'VOC2012/ImageSets/Main/trainval.txt'
            ],
            img_prefix=[data_root + 'VOC2012/'],
            pipeline=train_pipeline),
        pipeline=train_pipeline),
    val=dict(
        type=dataset_type,
        ann_file=data_root + 'VOC2012/ImageSets/Main/test.txt',
        img_prefix=data_root + 'VOC2012/',
        pipeline=test_pipeline),
    test=dict(
        type=dataset_type,
        ann_file=data_root + 'VOC2012/ImageSets/Main/test.txt',
        img_prefix=data_root + 'VOC2012/',
        pipeline=test_pipeline))
evaluation = dict(interval=50, metric='mAP', save_best='mAP')
# optimizer
optimizer = dict(
    lr=0.001, paramwise_cfg=dict(bias_lr_mult=2., bias_decay_mult=0.))
optimizer_config = dict(
    _delete_=True, grad_clip=dict(max_norm=35, norm_type=2))
# learning policy
lr_config = dict(
    policy='step',
    warmup='constant',
    warmup_iters=50,
    warmup_ratio=1.0 / 3,
    step=[6, 12, 20])
runner = dict(type='EpochBasedRunner', max_epochs=24)
'''
run time
'''
checkpoint_config = dict(interval=3)
# yapf:disable
log_config = dict(
    interval=10,
    hooks=[
        dict(type='TextLoggerHook'),
        dict(type='TensorboardLoggerHook')
    ])
# yapf:enable
dist_params = dict(backend='nccl')
log_level = 'INFO'
load_from = None
resume_from = None
workflow = [('train', 1)]
